package rmi;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class RMIClient {
    public static void main(String[] args) {
        try {
            // 获取本地主机上的RMI注册表
//            Registry registry = LocateRegistry.getRegistry("127.0.0.1", 1099);
            Registry registry = LocateRegistry.getRegistry("60.205.108.181", 1099);

            // 查找远程对象
            HelloService helloService = (HelloService) registry.lookup("HelloService");

            // 调用远程方法
            String response = helloService.sayHello("张三");
            System.out.println("收到服务端响应: " + response);
        } catch (Exception e) {
            System.err.println("客户端异常: " + e);
            e.printStackTrace();
        }
    }
}
